import React from 'react';
import axios from 'axios';
import IndexStaff from '../../component/IndexStaff/IndexStaff'
import IndexGoods from '../../component/IndexGoods/IndexGoods'
import '../../style/home.css'
class Home extends React.Component {
    constructor() {
        super()
        this.state = {
            //构造器里面的是私有状态，不提倡使用props赋值
            staffData:[],
            goodsData:[]
        }
    }
    render() {
        let {staffData,goodsData} = this.state
        return (
            <div className='homeBox'>
                <div className='homeStaff'>
                    <span>热门商品</span>
                    {goodsData.map(item=> <IndexGoods key={item.id} data={item} />)}
                </div>
                <div className='homeStaff'>
                    <span>员工信息展示</span>
                    {staffData.map(item=> <IndexStaff key={item.id} data={item} />)}
                </div>
            </div>
        )
    }
    componentDidMount(){
        axios({
            url:'http://123.57.67.148:3000/mock/195/getStaffData',
            method:'post',
        }).then(resp=>{
            let data = resp.data.data.filter(item =>{
                item.key = item.id
                //delete item.id
                return item
            })
            this.setState({
                staffData:data
            })
            //,()=>{console.log(this.state.staffData)}
            //setTimeout(()=>{console.log(this.state.staffData)},1000)
        })
        axios({
            url:'http://123.57.67.148:3000/mock/195/getIndexGoods',
            method:'post',
        }).then(resp=>{
            let data = resp.data.data.filter(item =>{
                item.key = item.id
                //delete item.id
                return item
            })
            this.setState({
                goodsData:data
            })
            //,()=>{console.log(this.state.goodsData)}
            //setTimeout(()=>{console.log(this.state.goodsData)},1000)
        })
    }
}
export default Home